<?php
/**
* 24tao后台明星标签设定
* author liwei
* date 2013-07-14
*/
class TagsAction extends Action {

	public function index(){
		$Tags = M('tags');
		$tagsInfo = $Tags->select();

		$this->assign('tagsinfo',$tagsInfo);
		$this->display();
	}
	//添加标签	
	public function add(){
		//判定添加还是修改标识
		$flag = $_POST['editid'];
		$Tags = D('tags');
		$data['tags_name'] = $_POST['tags_name'];
		$data['star_id'] = $_POST['star_id'];
		$data['create_time'] = date('Y-m-d H:i:s',time());
		if( !empty($data['tags_name']) && empty($flag) ){
			 if ( $Tags->create() ) {
                if ( false !== $Tags->add($data) ) {
                    $this->assign("jumpUrl","index");
                    $this->success('数据添加成功！');
                } else {
                    $this->assign("jumpUrl","index");
                    $this->error('数据写入错误');
                }
            }
		}elseif( !empty($data['tags_name']) && !empty($flag) ){
			if ( $Tags->create() ) {
				$data['id'] = $flag;
                if ( false !== $Tags->save($data) ) {
                    $this->assign("jumpUrl","index");
                    $this->success('数据添加成功！');
                } else {
                    $this->assign("jumpUrl","index");
                    $this->error('数据写入错误');
                }
            }
		}else{
			$Star = M('star');
			$starInfo = $Star->select();

			$this->assign('starinfo',$starInfo);
			$this->display();
		}
	}
	//修改标签
	public function edit(){
		$id = $_GET['id'];
		if( !empty($id) ){
			$Tags = M('tags');
			$editInfo = $Tags->where("id=$id")->select();
			
			$Star = M('star');
			$starInfo = $Star->select();

			$this->assign('starinfo',$starInfo);
			$this->assign('editInfo',$editInfo);
		}
		$this->display('add');
	}
	//删除标签
	public function del(){
		$id = $_GET['id'];
		if( !empty($id) ){
			$Tags = M('tags');
			$Tags->where("id=$id")->delete();
		}
		$this->display('add');
	}
}
